package com.ruoyi.youtian.controller;

import java.util.List;

import com.ruoyi.common.annotation.AutoSetDefaultParams;
import com.ruoyi.gzmx_tag.domain.Gzmx_tag;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.youtian.domain.TWorkspacePoint;
import com.ruoyi.youtian.service.ITWorkspacePointService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 点位与工作区关联Controller
 *
 * @author ruoyi
 * @date 2022-09-16
 */
@Controller
@RequestMapping("/youtian/workspaceCategoryPoint")
public class TWorkspacePointController extends BaseController
{
    private String prefix = "youtian/workspaceCategoryPoint";

    @Autowired
    private ITWorkspacePointService tWorkspacePointService;

    @RequiresPermissions("youtian:workspaceCategoryPoint:view")
    @GetMapping()
    public String workspaceCategoryPoint()
    {
        return prefix + "/workspaceCategoryPoint";
    }

    /**
     * 查询点位与工作区关联列表
     */
    @RequiresPermissions("youtian:workspaceCategoryPoint:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TWorkspacePoint tWorkspacePoint)
    {
        startPage();
        List<TWorkspacePoint> list = tWorkspacePointService.selectTWorkspacePointList(tWorkspacePoint);
        return getDataTable(list);
    }

    /**
     * 导出点位与工作区关联列表
     */
    @RequiresPermissions("youtian:workspaceCategoryPoint:export")
    @Log(title = "点位与工作区关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TWorkspacePoint tWorkspacePoint)
    {
        List<TWorkspacePoint> list = tWorkspacePointService.selectTWorkspacePointList(tWorkspacePoint);
        ExcelUtil<TWorkspacePoint> util = new ExcelUtil<TWorkspacePoint>(TWorkspacePoint.class);
        return util.exportExcel(list, "点位与工作区关联数据");
    }

    /**
     * 新增点位与工作区关联
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存点位与工作区关联
     */
    @RequiresPermissions("youtian:workspaceCategoryPoint:add")
    @Log(title = "点位与工作区关联", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    @AutoSetDefaultParams
    public AjaxResult addSave(TWorkspacePoint tWorkspacePoint)
    {
        return toAjax(tWorkspacePointService.insertTWorkspacePoint(tWorkspacePoint));
    }

    /**
     * 修改点位与工作区关联
     */
    @RequiresPermissions("youtian:workspaceCategoryPoint:edit")
    @GetMapping("/edit/{id}")
    @AutoSetDefaultParams
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TWorkspacePoint tWorkspacePoint = tWorkspacePointService.selectTWorkspacePointById(id);
        mmap.put("tWorkspacePoint", tWorkspacePoint);
        return prefix + "/edit";
    }

    /**
     * 修改保存点位与工作区关联
     */
    @RequiresPermissions("youtian:workspaceCategoryPoint:edit")
    @Log(title = "点位与工作区关联", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    @AutoSetDefaultParams
    public AjaxResult editSave(TWorkspacePoint tWorkspacePoint)
    {
        return toAjax(tWorkspacePointService.updateTWorkspacePoint(tWorkspacePoint));
    }

    /**
     * 删除点位与工作区关联
     */
    @RequiresPermissions("youtian:workspaceCategoryPoint:remove")
    @Log(title = "点位与工作区关联", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tWorkspacePointService.deleteTWorkspacePointByIds(ids));
    }


    /**
     * 工作区点位解除关联
     * @param tWorkspacePoint
     * @return
     */
    @GetMapping("/workspace-point-remove")
    @ResponseBody
    public AjaxResult  workspacePointRemove(TWorkspacePoint tWorkspacePoint){
        return  AjaxResult.success(tWorkspacePointService.deleteTWorkspacePointByTWorkspacePoint(tWorkspacePoint));
    }
}
